<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>Table</title>
		<link rel="stylesheet" href="/addons/hc_answer/template/plugins/layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="/addons/hc_answer/template/css/global.css" media="all">
		<link rel="stylesheet" type="text/css" href="/addons/hc_answer/template/plugins/font-awesome/css/font-awesome.css">
		<link rel="stylesheet" href="/addons/hc_answer/template/css/table.css" />
	</head>
	<body>
		<div class="admin-main">

			<blockquote class="layui-elem-quote">
				<a href="javascript:;" class="layui-btn layui-btn-small" id="refresh">
					<i class="layui-icon">&#x1002;</i> 刷新
				</a>
			</blockquote>
			<fieldset class="layui-elem-field">
				<legend>赛季活动</legend>
				<div class="layui-field-box">
					<table class="site-table table-hover">
						<thead>
							<tr>
								<th>用户头像</th>
								<th>昵称</th>
								<th>金额</th>
								<th>收款码</th>
								<th>提交时间</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>

				</div>
			</fieldset>
			<div class="admin-table-page">
				<div id="page" class="page">
				</div>
			</div>
		</div>
		<script type="text/javascript" src="/addons/hc_answer/template/plugins/layui/layui.js"></script>
		<script>
			layui.config({
				base: '/addons/hc_answer/template/plugins/layui/modules/'
			});

			layui.use(['icheck', 'laypage','layer'], function() {
				var $ = layui.jquery,
					laypage = layui.laypage,
					layer = parent.layer === undefined ? layui.layer : parent.layer;
				$('input').iCheck({
					checkboxClass: 'icheckbox_flat-green'
				});

				//page
				laypage({
					cont: 'page',
					pages: {$nums},
					groups: 10,
					jump: function(obj, first) {
						//得到了当前页，用于向服务端请求对应数据
						var curr = obj.curr;
						var html ='';
						$.ajax({
				            url:"{php echo $this->createWebUrl('activeajax');php}",
				            data:{page:curr},
				            type:"post",
				            dataType:"json",
				            success:function(data){
				            	layui.each(data.data, function(index, item){
				            		html += '<tr>';
							      	html += '<td><img src="'+item.avatar+'" style="width:50px"></td>';
				            		html += '<td>'+item.nickname+'</td>';
							      	html += '<td>'+item.money+'</td>';
							      	html += '<td><a data-code="'+item.moneycode+'" href="javascript:;" class="look">查看收款码</a></td>';
							      	html += '<td>'+item.addtime+'</td>';
							      	if(item.status==1){
							      		html += '<td><a href="javascript:;" data-id="'+item.id+'" class="layui-btn layui-btn-mini">已发放</a></td>';
							      	}else{
							      		html += '<td><a href="javascript:;" data-id="'+item.id+'" class="layui-btn layui-btn-danger layui-btn-mini send">确认发放</a></td>';
							      	}
							      	html += '</tr>';
							    });
							    $("tbody").html(html);
				            },
				            error:function(data){
				                layer.alert('请稍后重试', {icon: 5});
				            }
				        });
						
					}
				});
				
				$('#refresh').on('click', function() {
					location.reload();
				});

				$('tbody').on('click', '.look',function() {
					var img = $(this).attr('data-code')
					layer.open({
					  type: 1,
					  title: false,
					  closeBtn: 0,
					  area: '[200px,200px]',
					  skin: 'layui-layer-nobg', //没有背景色
					  shadeClose: true,
					  content: "<img src='"+img+"' style='width:400px'>"
					});
				});

				$('tbody').on('click', '.send',function() {
					var id = $(this).attr('data-id');
					var that = this
					layer.confirm('一经发放不能撤回，确定要发放吗？', {
						btn: ['确认','取消']
					}, function(){
						$.ajax({
				            url:"{php echo $this->createWebUrl('activedo');php}",
				            data:{id:id},
				            type:"post",
				            dataType:"json",
				            success:function(data){
				            	if(data.code=='1'){
				                	layer.alert(data.msg, {icon: 6});
				                	$(that).parent().html('<a href="javascript:;" class="layui-btn layui-btn-mini">已发放</a>');
				            	}else{
				                	layer.alert(data.msg, {icon: 5});
				            	}
				            },
				            error:function(data){
				                layer.alert('请稍后重试', {icon: 5});
				            }
				        });
					});
				});
			});
		</script>
	</body>

</html>